﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Cell))]
public class TCell : MonoBehaviour {
    
    private GameObject m_Target;

    private Cell m_Cell;

    public GameObject burstParticle;


    private void Awake() {
        m_Cell = GetComponent<Cell>();
    }

	private void Update () {
        // GameObject target = Distinguish();
        GameObject target = m_Cell.UpdateTarget(Attack);
        if (target != null) {
            m_Cell.FollowTarget(target);
            Debug.Log("Follow");
        } else {
            m_Cell.Wander();
        }
	}

    // 攻击目标
    public void Attack(GameObject target) {
        GameUIController.Instance.gameObject.GetComponent<AudioSource>().Play();
        
        GameObject particle = Instantiate(burstParticle, this.transform.position, Quaternion.identity);
        particle.transform.localEulerAngles = new Vector3(-90f,0,0);
        Destroy(target);
        Destroy(this.gameObject);
    }
}
